package com.autumn.platform.core.context.reqeust.impl;

import com.autumn.platform.core.Utils;
import com.autumn.platform.core.context.reqeust.IRequest;
import com.autumn.platform.core.context.track.Tracker;

public class Request implements IRequest {

    /**
     * 
     */
    private static final long serialVersionUID = -3822170273032982883L;

    /**
     * 唯一请求号
     */
    private final String requestId;

    /**
     * 唯一请求号
     */
    private String sessionId;

    /**
     * 请求目标
     */
    private String target;

    /**
     * 请求协议
     */
    private String protocol;

    /**
     * 服务器IP
     */
    private final String serverIp;

    /**
     * 服务器操作系统
     */
    private final String serverOs;

    /**
     * 请求时间
     */
    private final long time;

    public Request(String sessionId) {
        if (!Tracker.isTracking()) {
            Tracker.start();
        }
        this.requestId = Tracker.getCurrentTrackId();
        this.sessionId = sessionId;
        this.time = System.currentTimeMillis();
        this.serverIp = Utils.LOCALE_HOST;
        this.serverOs = Utils.LOCALE_OS;
    }

    @Override
    public String getRequestId() {
        return this.requestId;
    }

    @Override
    public String getSessionId() {
        return sessionId;
    }

    @Override
    public void changeSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    @Override
    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    @Override
    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    @Override
    public String getServerIp() {
        return serverIp;
    }

    @Override
    public String getServerOs() {
        return serverOs;
    }

    @Override
    public long getTime() {
        return time;
    }
}
